//
//  WDKeyInfoController.m
//  OpenSesame
//
//  Created by zhangjiaming on 17/5/11.
//  Copyright © 2017年 OpenSesame. All rights reserved.
//

#import "WDKeyInfoController.h"
#import "JMFrequencyViewController.h"
#define KEYINFO @"http://47.92.139.238/copying/index/keyInfo"
@interface WDKeyInfoController ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *pinlvLabel;
@property (weak, nonatomic) IBOutlet UILabel *shipeiLabel;
@property (weak, nonatomic) IBOutlet UILabel *sayLabel;

@property (weak, nonatomic) IBOutlet UILabel *jishuLabel;
@property (weak, nonatomic) UIButton *bluetoothBtn;
- (IBAction)beizhuBtn:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIButton *beizhu;
@end

@implementation WDKeyInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 60, 44);
    [btn setImage:[UIImage imageNamed:@"蓝牙 未连"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"蓝牙 按下"] forState:UIControlStateHighlighted];
    [btn setImage:[UIImage imageNamed:@"蓝牙"] forState:UIControlStateSelected];
    [btn addTarget:self action:@selector(settingBlueTooth) forControlEvents:UIControlEventTouchUpInside];
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -25);
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.bluetoothBtn = btn;
    self.title = _nameStr;
    [self getdata];
}

-(void)getdata{
    NSUserDefaults *defult =[NSUserDefaults standardUserDefaults];
    WDLog(@"%@",[defult objectForKey:@"token"]);
    NSDictionary *dic = @{@"token":[defult objectForKey:@"token"],
                          @"keyId":_keyId,
                          };
    [JMHttpTool post:KEYINFO param:dic success:^(id responseObject) {
    
        NSDictionary *dict =[NSDictionary dictionaryWithDictionary:responseObject];
        WDLog(@"%@",dict[@"data"]);
        WDLog(@"%@",dict);
        NSString *imgUrl =[NSString stringWithFormat:@"%@%@",BASEURL,dict[@"data"][@"pic"]];
        [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:[UIImage imageNamed:@"详情图"]];
        self.pinlvLabel.text = dict[@"data"][@"frequency"];
        self.shipeiLabel.text  = dict[@"data"][@"fit"];
    
        self.jishuLabel.text = dict[@"data"][@"content"];
        //self.beizhu.titleLabel.text = dict[@"data"][@"remark"];
    } frail:^(NSError *error) {
        WDLog(@"%@",error);
    }];
}
// 设置蓝牙
-(void)settingBlueTooth{
    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        [[UIApplication sharedApplication] openURL:url];
    }
}
- (IBAction)kaobeiBtn:(UIButton *)sender {
     [self.navigationController pushViewController:[[JMFrequencyViewController alloc] init] animated:YES];
}
- (IBAction)shengBtn:(UIButton *)sender {
     [self.navigationController pushViewController:[[JMFrequencyViewController alloc] init] animated:YES];
}
- (IBAction)testBtn:(UIButton *)sender {
     [self.navigationController pushViewController:[[JMFrequencyViewController alloc] init] animated:YES];
}
- (IBAction)comperBtn:(UIButton *)sender {
     [self.navigationController pushViewController:[[JMFrequencyViewController alloc] init] animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (IBAction)beizhuBtn:(UIButton *)sender {
    // 填写个人备注
    
}
@end
